<template>
	<view class="classify">
		<view class="utab">
			<u-tabs-swiper ref="uTabs" :list="mainnav" :current="current" @change="tabsChange" :is-scroll="false"
				swiperWidth="750" active-color="#f9834a"></u-tabs-swiper>
		</view>

		<swiper :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
			<swiper-item class="swiper-item">
				<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
					<view class="second">
						<view class="second-item" v-for="(i,ind) in second1" :key="ind" @click="switchSecond(i.url)">
							<!-- <view class="item-img">
								<image :src='`../../static/nang/nang${ind}.jpg`' mode=""></image>
							</view> -->
							<view class="item-text">
								{{i.name}}
							</view>
						</view>
					</view>

				</scroll-view>
			</swiper-item>
			<swiper-item class="swiper-item">
				<scroll-view scroll-y style="height: 750px;width: 100%;" @scrolltolower="onreachBottom">
					<view class="second">
						<view class="second-item" v-for="(i,ind) in second2" :key="ind" @click="switchSecond(i.url)">
							<!-- <view class="item-img">
								<image src="../../static/1.jpg" mode=""></image>
							</view> -->
							<view class="item-text">
								{{i.name}}
							</view>
						</view>
					</view>

				</scroll-view>
			</swiper-item>
			<swiper-item class="swiper-item">
				<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
					<view class="second">
						<view class="second-item" v-for="(i,ind) in second3" :key="ind" @click="switchSecond(i.url)">
							<!-- <view class="item-img">
								<image src="../../static/1.jpg" mode=""></image>
							</view> -->
							<view class="item-text">
								{{i.name}}
							</view>
						</view>
					</view>

				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		getClassifyNav,
		getSecondClassifyNav,
		getSecondClassifyResult
	} from "../../api/index.js"
	export default {
		data() {
			return {
				second: [],
				second1: [{
						"name": "都市",
						"cover": "https://easyreadfs.nosdn.127.net/khh7UJpoQObEsWa9GcddRw==/8796093022817550996",
						"desc": 85427,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=7",
						"module": 30
					},
					{
						"name": "玄幻",
						"cover": "https://easyreadfs.nosdn.127.net/n8-OQw4ARPkvvCeBm6OoQg==/8796093022817551786",
						"desc": 43697,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=1",
						"module": 30
					},
					{
						"name": "悬疑",
						"cover": "https://easyreadfs.nosdn.127.net/aMCcBwP4cDPakhVmuHe_oQ==/8796093022817550956",
						"desc": 15624,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=5",
						"module": 30
					},
					{
						"name": "历史",
						"cover": "https://easyreadfs.nosdn.127.net/pbaK7_nbiYfjAsIO7sFzRQ==/8796093022817554740",
						"desc": 5866,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=11",
						"module": 30
					},
					{
						"name": "军事",
						"cover": "https://easyreadfs.nosdn.127.net/Aqnzm1HQDFb1tyHxKhBP9A==/8796093022817550885",
						"desc": 2243,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=3",
						"module": 30
					},
					{
						"name": "科幻",
						"cover": "https://easyreadfs.nosdn.127.net/8heOtyG3NrXlzZEDhJnTUg==/8796093022817553545",
						"desc": 5855,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2",
						"module": 30
					},
					{
						"name": "同人",
						"cover": "https://easyreadfs.nosdn.127.net/t-Jq7P4CFffQvwqcCHiTKA==/8796093022817557009",
						"desc": 4113,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=10",
						"module": 30
					},
					{
						"name": "短篇",
						"cover": "https://easyreadfs.nosdn.127.net/saO139SOiG3R9_Kd8RNzmQ==/8796093022817552949",
						"desc": 1252,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=12",
						"module": 30
					}
				],
				second2: [{
						"name": "玄幻",
						"cover": "",
						"desc": 0,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=26",
						"module": 30
					},
					{
						"name": "科幻",
						"cover": "",
						"desc": 0,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=27",
						"module": 30
					},
					{
						"name": "悬疑",
						"cover": "",
						"desc": 0,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=28",
						"module": 30
					},
					{
						"name": "传奇",
						"cover": "",
						"desc": 0,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=29",
						"module": 30
					},
					{
						"name": "脑洞",
						"cover": "",
						"desc": 0,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=31",
						"module": 30
					},
					{
						"name": "年代",
						"cover": "",
						"desc": 0,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=32",
						"module": 30
					},
					{
						"name": "重生",
						"cover": "",
						"desc": 0,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=33",
						"module": 30
					},
					{
						"name": "现言",
						"cover": "https://easyreadfs.nosdn.127.net/HZ9sDOU1tqlQquNVPuP-YA==/8796093022817556522",
						"desc": 44105,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=8",
						"module": 30
					},
					{
						"name": "穿越",
						"cover": "https://easyreadfs.nosdn.127.net/WyucxlpJf5TmcwQPfyk4Kg==/8796093022817556544",
						"desc": 26906,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=9",
						"module": 30
					},
					{
						"name": "宫斗",
						"cover": "https://easyreadfs.nosdn.127.net/JzPwfR7gqjxnRufwHy7xoQ==/8796093022817562524",
						"desc": 8045,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=18",
						"module": 30
					},
					{
						"name": "古言",
						"cover": "https://easyreadfs.nosdn.127.net/10Z465FbA_kAFp0XDnWzYQ==/8796093022817561178",
						"desc": 31377,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=24",
						"module": 30
					},
					{
						"name": "短篇",
						"cover": "https://easyreadfs.nosdn.127.net/0uzR0e1BakKnAJiqZcHsCQ==/8796093022817556494",
						"desc": 1258,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=16",
						"module": 30
					},
					{
						"name": "校园",
						"cover": "https://easyreadfs.nosdn.127.net/CdO-5atcRg9gSdo_HEI7mQ==/8796093022817557983",
						"desc": 18367,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=22",
						"module": 30
					},
					{
						"name": "仙侠",
						"cover": "https://easyreadfs.nosdn.127.net/5bp00TlXCGQqLjxLrAY3_Q==/8796093022817556768",
						"desc": 6387,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=13",
						"module": 30
					},
					{
						"name": "种田",
						"cover": "https://easyreadfs.nosdn.127.net/pHidXL1Mc34ELt-VGmpaZQ==/8796093022817557922",
						"desc": 6544,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=17",
						"module": 30
					},
					{
						"name": "同人",
						"cover": "https://easyreadfs.nosdn.127.net/rhAbCH9S4g7Skycc0e7arw==/8796093022817557387",
						"desc": 1521,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=15",
						"module": 30
					}
				],
				second3: [{
						"name": "小说",
						"cover": "https://easyreadfs.nosdn.127.net/yn1Ti-zK3i0LJCfA4kR67w==/8796093022817545901",
						"desc": 27371,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2000",
						"module": 30
					},
					{
						"name": "人文",
						"cover": "https://easyreadfs.nosdn.127.net/zKTOxIRRDKr2plCpZhrqeA==/8796093022817548277",
						"desc": 37664,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2300",
						"module": 30
					},
					{
						"name": "生活",
						"cover": "https://easyreadfs.nosdn.127.net/qR6GDplQLg_Hxl-fn-bMtw==/8796093022817552556",
						"desc": 10698,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2800",
						"module": 30
					},
					{
						"name": "两性",
						"cover": "https://easyreadfs.nosdn.127.net/NRu9OSuJWRfODDJuGXTV0g==/8796093022817549285",
						"desc": 615,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2500",
						"module": 30
					},
					{
						"name": "励志",
						"cover": "https://easyreadfs.nosdn.127.net/_7ElEran36aVYi-3nPw-eA==/8796093022817550692",
						"desc": 9641,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2600",
						"module": 30
					},
					{
						"name": "经管",
						"cover": "https://easyreadfs.nosdn.127.net/Hj93KbhnNim5crcPx_vTTA==/8796093022817550626",
						"desc": 9763,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2400",
						"module": 30
					},
					{
						"name": "文学",
						"cover": "https://easyreadfs.nosdn.127.net/JvBIj-p-7i918D6RjBgR_g==/8796093022817550313",
						"desc": 16553,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2100",
						"module": 30
					},
					{
						"name": "艺术",
						"cover": "https://easyreadfs.nosdn.127.net/JioZ-vLgf-32GLV11s5Pkg==/8796093023021510266",
						"desc": 3021,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2200",
						"module": 30
					},
					{
						"name": "科普",
						"cover": "https://easyreadfs.nosdn.127.net/LyHmQIJXnw_3GcNHO_vMUQ==/8796093022817549813",
						"desc": 16670,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2900",
						"module": 30
					},
					{
						"name": "育儿",
						"cover": "https://easyreadfs.nosdn.127.net/0ecJu1lZeuMxE1L-XOEjXw==/8796093022817547898",
						"desc": 4316,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=2700",
						"module": 30
					},
					{
						"name": "IT",
						"cover": "https://easyreadfs.nosdn.127.net/QBmhImByjkigBz1HNElm1g==/8796093023021505130",
						"desc": 825,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=3000",
						"module": 30
					},
					{
						"name": "教辅",
						"cover": "https://easyreadfs.nosdn.127.net/jiHeET57Vc2fIqbQ6t0hRw==/8796093023021499352",
						"desc": 3254,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=3100",
						"module": 30
					},
					{
						"name": "外文",
						"cover": "https://easyreadfs.nosdn.127.net/0U-3-0HOv97oyhEGEYNjUQ==/8796093022817548456",
						"desc": 24500,
						"p_action": "113",
						"url": "/source/v2/cat.json?catId=3200",
						"module": 30
					}
				],
				// mainnav: [],
				mainnav: [{
						"name": "男生",
						"id": "b666f412aab94fd0b44278602331cfe8",
						"node": [{
							"name": "分类",
							"id": "244f55f3af7841c9a71dd912c1f6bc26",
							"url": "/store/info.json?type=male&bar=cat&uuid=244f55f3af7841c9a71dd912c1f6bc26"
						}],
						"select": true
					},
					{
						"name": "女生",
						"id": "78db012768c14914afda56f1e6858b73",
						"node": [{
							"name": "分类",
							"id": "d6f496cf3b45479795fe087dbb5ea90a",
							"url": "/store/info.json?type=female&bar=cat&uuid=d6f496cf3b45479795fe087dbb5ea90a"
						}],
						"select": false
					},
					{
						"name": "出版",
						"id": "10d810f502e944fc9aabf1097b7bd9cc",
						"node": [{
							"name": "分类",
							"id": "8be5f5f01af141fdbc0936350a786f9e",
							"url": "/store/info.json?type=publish&bar=cat&uuid=8be5f5f01af141fdbc0936350a786f9e"
						}],
						"select": false
					}
				],
				// 因为内部的滑动机制限制，请将tabs组件和swiper组件的current用不同变量赋值
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
			};
		},
		onLoad() {
			// this.getclassifyNav()
			// this.init()
		},
		methods: {
			switchSecond(myurl) {
				console.log(myurl)
				uni.navigateTo({
					url: `../filtrate/filtrate?myurl=${myurl}`
				})

			},
			// async getclassifyNav() {
			// 	await getClassifyNav().then(res => {
			// 		this.mainnav = res.books.slice(0, 3)
			// 		console.log(this.mainnav);
			// 	})
			// },
			// tabs通知swiper切换
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
				getSecondClassifyNav(this.mainnav[current].node[0].url).then(res => {
					this.second = res.list[0].labels
					console.log(this.second, res);
				})
			},
			init() {
				// getClassifyNav().then(res => {
				// this.mainnav = res.books.slice(0, 3)
				let myurl = this.mainnav[0].node[0].url
				getSecondClassifyNav(myurl).then(res => {
					this.second = res.list[0].labels
				})
				// })
			},
			// scroll-view到底部加载更多
			onreachBottom() {

			}
		}
	};
</script>
<style lang="scss">
	.classify {
		.utab {
			border-bottom: 1px solid #f5f5f5;
			box-sizing: border-box;
			padding-bottom: 20rpx;
		}

		.second {
			// height: 1050rpx;
			overflow: scroll;
			// margin: 10px 0;
			display: flex;
			flex-wrap: wrap;
			box-sizing: border-box;
			padding: 10px;
			justify-content: space-between;

			.second-item {
				background-image: url("../../static/nangbc.png");
				background-repeat: no-repeat;
				// background-size: cover;
				// background-position: 100px 100px;
				border-radius: 12px;
				width: 48%;
				// background-color: #f3f3f3;
				margin: 5px 0;
				box-sizing: border-box;
				font-size: 15px;
				display: flex;
				padding: 10px;
				align-items: center;

				&.active {
					color: #f68149;
				}

				.item-img {

					// width: 50px;
					// height: 50px;
					// width: 90px;
					// height: 110px;
					image {
						border-radius: 12px;
						width: 100%;
						height: 100%;
					}
				}

				.item-text {

					flex: 1;
					display: flex;
					justify-content: center;
				}
			}
		}
	}

	uni-swiper {
		height: 1070rpx;
	}
</style>